package com.kang.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.kang.dao.SupplierMapper;
import com.kang.pojo.Supplier;
import com.kang.service.SupplierService;
import com.vonechina.entity.page.SupplierPage;

@Service("SupplierService")
public class SupplierSericeImpl implements SupplierService {

	@Resource
	private SupplierMapper sl;
	
	@Override
	public List<Supplier> listSupplier(SupplierPage page){
		 page.setRows(sl.countSupplier(page));
		return sl.listSupplier(page);
	}
	
	@Override
	public List<Supplier> listAllSupplier(){
		SupplierPage page=new SupplierPage();
		page.setPage(false);
		return sl.listSupplier(page);
	}

	@Override
	public int deleteByPrimaryKey(Integer supplierid) {

		return sl.deleteByPrimaryKey(supplierid);
	}

	@Override
	public int insertSelective(Supplier record) {

		return sl.insertSelective(record);
	}

	@Override
	public Supplier selectByPrimaryKey(Integer supplierid) {

		return sl.selectByPrimaryKey(supplierid);
	}

	@Override
	public int updateByPrimaryKeySelective(Supplier record) {

		return sl.updateByPrimaryKeySelective(record);
	}

	@Override
	public String generateSupplierCode() {
		SimpleDateFormat sdf=new SimpleDateFormat("yy");
		String text=sdf.format(new Date())+"001";
		Long no=Long.parseLong(text);
		String max=sl.selectMaxCode();
		Long l=0l;
		if(max!=null){
			l=Long.parseLong(max.replaceAll("[a-zA-Z]", ""));
		}
		if(l>=no){
			no=l+1;
		}
		return ""+no;
	}

}
